#include <bits/stdc++.h>
using namespace std;
#include <iostream>
class Solution
{
public:
    bool isMatch(string s, string p)
    {
        // dp[i][j]
        // j == '*'  dp[i][j] = (dp[i-1][j] && (s[i-1] mc s[i-2])) || dp[i][j-2]
        // else dp[i][j] = dp[i-1][j-1] && s[i-1] mc s[j-1]
        int n = s.size(), m = p.size();
        vector<vector<bool>> dp(n + 1, vector<bool>(m + 1, false));
        dp[0][0] = true;
        for (int j = 2; j <= m && p[j - 1] == '*'; j += 2)
        {
            dp[0][j] = true;
        }
        for (int i = 1; i <= n; ++i)
        {
            char si = s[i - 1];
            for (int j = 1; j <= m; ++j)
            {
                char pj = p[j - 1];
                if (pj == '*') // j >= 2
                {
                    char pjbefore = p[j - 2];
                    dp[i][j] =
                        (dp[i - 1][j] && (si == pjbefore || pjbefore == '.')) ||
                        dp[i][j - 2];
                }
                else
                {
                    dp[i][j] = dp[i - 1][j - 1] && (si == pj || pj == '.');
                }
            }
        }
        return dp[n][m];
    }
};
int main()
{

    // system("pause");
    return 0;
}
